#!/usr/bin/env python
#-*- coding:utf-8 -*-

'''
Created on 2012-01-15

@author: zhangchong
'''


#/data/log/log/[0-9,a-z]*/[0-9]*[0-9]

import sys
import os
import json
import string
import MySQLdb
import simplejson
import Config
import datetime

import CpLog
import Split
import Statist



import accuTotal
import accuUserPerDay
import newUserPerDay

import traceback

from Statist import *
from Tools import connectMySQL
from Tools import getPid


def main(date=""):
    if(date == ""):
        yesterday = datetime.date.today() - datetime.timedelta(days=1)
        format = "%Y%m%d"
        yesterday = yesterday.strftime("%Y%m%d")
        yesterday = str(yesterday)
   
        argv = sys.argv
        try:
            date = argv[1]
        except:
            date = yesterday
    
    #建立log目录
    if(not os.path.exists(Config.ScriptsDir + "log")):
       os.makedirs(Config.ScriptsDir + "log")
    else:
       if(not os.path.isdir(Config.ScriptsDir + "log")):     
            os.makedirs(Config.ScriptsDir + "log")
               
    statdate = date
    
    isSplit = True
    try:
        argv2 = argv[2]
        if(str(argv2) == "sort"):
            isSplit = False
    except:
        isSplit = True 
        
        
    cmd = "rm -fr  /opt/jsloadertmp.log" 
    print cmd
    result = os.popen(cmd)
    result = result.read()
    print result      
    
    logPath = SaveLogDir + "statis_log_" + statdate + "_sort"           
    CpLog.cpLog(statdate, type="statis")
    cmd = "mv " + logPath + " /opt/jsloadertmp.log" 
    print cmd
    result = os.popen(cmd)
    result = result.read()
    print result  
    
    jsloader = JsLoader_InitialUuid(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")  
    
    jsloader = JsLoader_Initial(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")
    
    jsloader = JsLoader_InitialGuid(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")
    
    jsloader = JsLoader_InitialNoGuid(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")
    
    jsloader = JsLoader_VVDetail(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")
    
    jsloader = JsLoader_VVBegin(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")  
     
    jsloader = JsLoader_VVEnd(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log") 
      
    jsloader = JsLoader_VV(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")   
    
    jsloader=JsLoader_VVBegin_Html5Mp4Download(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log") 
    
    jsloader=JsLoader_VVBegin_Html5Mp4Error(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log") 
    
    jsloader=JsLoader_VVBegin_Html5Mp4(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")
    
    jsloader=JsLoader_VVBegin_AndroidM3u8(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")
    
    jsloader=JsLoader_VVBegin_iOSM3u8(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")
    
    jsloader=JsLoader_VVBegin_NoAdapterParam(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")
    
    jsloader=JsLoader_VVBegin_Flash(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")
    
    jsloader = VV_Begin(statdate)
    statist(jsloader, isSplit=isSplit, logPath="/opt/jsloadertmp.log")  
    
    
    
#    cmd = "rm -fr  /opt/jsloadertmp.log" 
#    print cmd
#    result = os.popen(cmd)
#    result = result.read()
#    print result  


if __name__ == "__main__":
    
    main()
   
   
   
    
    
    
    
   
